package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmDownOrUpDto;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author xiaquanen
 * @version 1.0
 * @project heima-leadnews
 * @date 2024/7/22 09:54:00
 */
@RestController
@RequestMapping("api/v1/news")
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 新闻列表查询
     *
     * @return
     */
    @PostMapping("/list")
    public ResponseResult newsList(@RequestBody WmNewsPageReqDto wmNewsPageReqDto)
    {
        return wmNewsService.newsList(wmNewsPageReqDto);
    }

    /**
     * 文章的上下架
     *
     * @return
     */
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmDownOrUpDto dto)
    {
        //调用service层进行操作
        return wmNewsService.downOrUp(dto);
    }

    /**
     * 上传或者修改文章
     *
     * @param wmNewsDto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto wmNewsDto)
    {
        return wmNewsService.submitNews(wmNewsDto);
    }

    /**
     * 用于数据回显
     *
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult findOne(@PathVariable("id") Integer id)
    {
        WmNews wmNews = wmNewsService.getById(id);
        return ResponseResult.okResult(wmNews);
    }

    /**
     * 删除文章
     *
     * @param id
     * @return
     */
    @GetMapping("/del_news/{id}")
    public ResponseResult delNews(@PathVariable("id") Integer id)
    {
        return wmNewsService.delNews(id);
    }


}
